#include<bits/stdc++.h>
using namespace std;
int t,n,ma;
int a[20];
int rs[20];
int vis[100005];
int check(){
	int sum=0;
	vector<int>fz[2];
	for(int i=1;i<=n;i++){
		if(fz[rs[i]].size()&&fz[rs[i]].back()==a[i])sum+=a[i];
		fz[rs[i]].push_back(a[i]);
	}
	return sum;
}
void dfs(int b){
	if(b>n){
		ma=max(check(),ma);
		return;
	}
	rs[b]=0;
	dfs(b+1);
	rs[b]=1;
	dfs(b+1);
}
int main(){
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	cin>>t;
	while(t--){
		memset(rs,0,sizeof(rs));
		ma=0;
		cin>>n;
		if(n>=20){
			int s=0;
			for(int i=1;i<=n;i++){
				int x;
				cin>>x;
				if(vis[x])s+=x;
				vis[x]=1;
			}
			cout<<s<<"\n";
			continue;
		}
		for(int i=1;i<=n;i++){
			cin>>a[i];
		}

		dfs(1);
		cout<<ma<<"\n";
	}
	return 0;
}
